package com.maozzi.common.model;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * 返回值基类
 *
 * @author maozi
 */
@Data
@NoArgsConstructor
public class PageVO<T> implements Serializable {
    /**
     * 当前页码
     */
    private Long page;
    /**
     * 每页数量
     */
    private Long pageSize;
    /**
     * 总页数
     */
    private Long pageNum;
    /**
     * 总数
     */
    private Long total;
    /**
     * true - 有下一页，false - 否
     */
    private Boolean hasNext;
    /**
     * 数据
     */
    private List<T> items;

    public PageVO(Long page, Long pageSize) {
        this(page, pageSize, null, null, null);
    }

    public PageVO(Long page, Long pageSize, Long pageNum, Long total, List<T> items) {
        this.page = page;
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.total = total;
        if (page != null && pageNum != null) {
            this.hasNext = page < pageNum;
        } else {
            this.hasNext = Boolean.FALSE;
        }
        this.items = items;
    }
}
